<?php
declare (strict_types=1);

namespace app\common\model;

class AreaCensus extends Base
{
    protected $name = 'area_census';

    public function c()
    {
        return $this->hasOne(Area::class, 'code', 'city')->field('code,city as title');
    }

    public static function saves($city,$amount)
    {
         $info = AreaCensus::where('city',$city)->find();
         if(isset($info))
         {
             $info->amount = $info->amount+$amount;
             $info->num = $info->num+1;
             $info->save();
         }else{
             $data['city'] = $city;
             $data['amount'] = $amount;
             $data['num'] = 1;
             AreaCensus::create($data);
         }
    }

}
